import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import SuiVue from 'semantic-ui-vue';
import 'semantic-ui-css/semantic.min.css';
import './utils/api'                            //引入api
import axios from 'axios'
import VueClipboard from 'vue-clipboard2'      //引入复制插件
// import {Base64} from 'js-base64'                 //引入base64加密

// Vue.use(Base64);
Vue.use(VueClipboard);
Vue.use(ElementUI);
Vue.use(SuiVue);
Vue.config.productionTip = false;


//全局注册数据请求方法
Vue.prototype.$https = axios
axios.defaults.baseURL = 'http://1.14.48.193:8888';

router.beforeEach((to, from, next) => {
  if (to.matched.some((r) => r.meta.requireAuth)) {
    let token = sessionStorage.getItem('token');
    if (token) {   //判断是否已经登录
      next();
    } else {
      next({
        path: '/',
      });
    }
  } else {
    next();
  }
  //如果本地 存在 token 则 不允许直接跳转到 登录页面
  if(to.fullPath === "/" || to.fullPath === "/Register"){
    if(sessionStorage.getItem('token')){
      next({
        path:'/Home/index'
      });
    }else {
      next();
    }
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
